package com.zxx.pattern.statePattern.state;

/**
 * 正在发放糖果的状态
 *
 * @author zxx on 2021/1/14
 */
public class StateCandyPopping implements State {

    private CandyMachine candyMachine;

    public StateCandyPopping(CandyMachine candyMachine) {
        this.candyMachine = candyMachine;
    }

    @Override
    public void onMoneyInserted() {
        System.out.println("正在发放糖果，请勿操作！");
    }

    @Override
    public void onMoneyReturned() {
        System.out.println("正在发放糖果，请勿操作！");
    }

    @Override
    public void onCrankTurned() {
        System.out.println("正在发放糖果，请勿操作！");
    }

    @Override
    public void onCandyPoped() {
        candyMachine.setCandyCount(candyMachine.getCandyCount() - 1);//5-1=4
        System.out.println("成功发放了一颗糖果！");

        //设置状态为StateNoMoney（没有投币的状态）
        candyMachine.setState(candyMachine.getNoMoneyState());
    }
}
